<?php
namespace Plugin\Controller;
use Think\Controller;
/**
 * Appframe项目公共Action
 */
class VerifyController extends Controller 
{
    protected $notUrlArr;
    public function _initialize()
    {
        $this->notUrlArr = array('home','develop','site','plugin','business','account','admin','article','category','common','page','leavemsg','content','member');
    }
    public function verify($id) {  
        $config =   array(    
            'fontSize'    =>    20,    // 验证码字体大小    
            'length'      =>    4,     // 验证码位数    
            'useNoise'    =>    false, // 关闭验证码杂点
            'useCurve'    =>    false, // 关闭  
        );
        $Verify =     new \Think\Verify($config);
        $Verify->entry($id);
    }  
    
    public function check_verify($code, $id = '')
    {    
        $verify = new \Think\Verify();    
        return $verify->check($code, $id);
    }
    public function validVerify($id = '')
    {
        $verify = new \Think\Verify();    
        $code =  I('post.param','0','htmlspecialchars');
        $result = $verify->check($code, $id);
        if($result){
            echo "y";
        }else{
          echo "<i class='icon-warning-sign'></i> 验证码错误";
        }
    }
    function notUrl($url){
      if (empty($url)) {
        return false;
      }
      $url=strtolower($url);
      if(in_array($url, $this->notUrlArr)){
        return false;
      }else{
        return true;
      }
    }
    public function validNoUrl($m='article')
    {
        $url =  I('post.param','0','htmlspecialchars');
        if ($this->notUrl($url)) {
          $urlObj = M($m);
          $map['url']=$url; 
          $result = $urlObj->where($map)->count();
          if(empty($result)){
            echo "y";
          }else{
            echo "<i class='icon-warning-sign'></i> 此链接已存在";
          }
        }else{
           echo "<i class='icon-warning-sign'></i> 此链接无效";
        }
    }
    public function validNoUrl2($m='article')
    {
        $oid = I('get.oid','0','htmlspecialchars');
        $url = I('post.param','0','htmlspecialchars');
        if ($this->notUrl($url)) {
            $urlObj = M($m);
            $result = $urlObj->field('url')->find($oid);
            if(!empty($result)){
               if($result['url']==$url){
                  echo "y";
               }else{
                  $map['url'] = $url;
                  $count = $urlObj->where($map)->count();
                  if(empty($count)){
                      echo "y";
                  }else{
                      echo "<i class='icon-warning-sign'></i> 此链接已存在";
                  }
               }
            }
        }else{
           echo "<i class='icon-warning-sign'></i> 此链接无效";
        }
    }
}    
?>
